#include<iostream>

using ll = long long;
using namespace std;
const int N = 1e5 + 10;
int a[N];
int main()
{
    int n;
    cin >> n;
    int p = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] == i) p++;
    } 
    if (n == p) cout << p << endl;
    else
    {
        for (int j = 0; j < n; j++)
        {
            if (a[j] != j && j == a[a[j]])
            {
                p += 2;
                cout << p << endl;
                return 0;
            }
        }
        cout << p + 1 << endl;
    }

    return 0;
}